from datetime import datetime, timedelta

from binance import Client

from SecretData import api_key, api_secret

# ConfigurationData.py
class ConfigurationData:
    successCount = 0
    orderingCount = 0

#--------修改区-----------
symbol = 'BNBUSDT'#量化的对象
leverage = 10#量化的倍数
retries = 10 #失败后尝试的次数，建议不修改
timeNum = 600 #十分钟间隔
QuantitativeSensitivity = 3# 量化敏锐度------------------------暂定小级别测试
#-----------------------
def initS(symbol):

    # 获取当前日期
    today = datetime.now()
    start_of_day = datetime(today.year, today.month, today.day)

    # 获取昨天同一时间以确保我们获取完整的当日数据
    yesterday = start_of_day - timedelta(days=1)
    klines = client.get_historical_klines(symbol, Client.KLINE_INTERVAL_1DAY, yesterday.strftime("%d %b, %Y"),
                                          today.strftime("%d %b, %Y"))

    if klines:
        # 最新的k线数据是最接近当前时间的完整日数据
        latest_kline = klines[0]
        open_price = float(latest_kline[1])
        highest_price = float(latest_kline[2])
        lowest_price = float(latest_kline[3])

        # 计算最高价与最低价之差相对于开盘价的百分比
        price_change_percentage = ((highest_price - lowest_price) / open_price) * 100

        return price_change_percentage
    else:
        return None

# 创建Binance客户端实例
client = Client(api_key, api_secret)



getNum = initS(symbol) * QuantitativeSensitivity
#按照百分比来设置参数
letNum = getNum/2;
profit_threshold = getNum/leverage  # 盈利阈值为2%